package leoner.javascript;

import java.io.InputStreamReader;
import java.io.Reader;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class LoopBean {
	public static void main(String[] args) throws ScriptException, NoSuchMethodException {
		ScriptEngineManager manager = new ScriptEngineManager();
		ScriptEngine engine = manager.getEngineByName("javascript");
		Person p = new Person();
		p.setAge(21);
		p.setName("kang");
		Reader reader = new InputStreamReader(LoopBean.class.getResourceAsStream("LoopBean.js"));
		engine.eval(reader);
		Invocable inv = (Invocable)engine;
		Person p1 = (Person)inv.invokeFunction("test", p);
		System.out.println(p1);
	}
	static class Person{
		private String name;
		private int age;
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public int getAge() {
			return age;
		}
		public void setAge(int age) {
			this.age = age;
		}
		@Override
		public String toString(){
			return "name:"+name+",age:"+age;
		}
		
	}
}
